package com.hkts.naturalgas.dictionaries.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hkts.naturalgas.association.service.IHktsRequestAddressAssociationService;
import com.hkts.naturalgas.dictionaries.entity.HktsEnvironmentProtectionDictionaries;
import com.hkts.naturalgas.dictionaries.mapper.HktsEnvironmentProtectionDictionariesMapper;
import com.hkts.naturalgas.dictionaries.service.IHktsEnvironmentProtectionDictionariesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.ArrayList;
import java.util.List;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yck
 * @since 2021-06-23
 */
@Service
@Transactional
public class HktsEnvironmentProtectionDictionariesServiceImpl extends ServiceImpl<HktsEnvironmentProtectionDictionariesMapper, HktsEnvironmentProtectionDictionaries> implements IHktsEnvironmentProtectionDictionariesService {


    @Autowired
    private HktsEnvironmentProtectionDictionariesMapper hktsEnvironmentProtectionDictionariesMapper;


    @Autowired
    private IHktsRequestAddressAssociationService iHktsRequestAddressAssociationService;

    @Override
    public IPage<HktsEnvironmentProtectionDictionaries> selectPage(Page<HktsEnvironmentProtectionDictionaries> page, HktsEnvironmentProtectionDictionaries hktsEnvironmentProtectionDictionaries){
            QueryWrapper<HktsEnvironmentProtectionDictionaries> query=Wrappers.query();
            QueryWrapper<HktsEnvironmentProtectionDictionaries> entityWrapper=getEntityWrapper(query, hktsEnvironmentProtectionDictionaries);
            return hktsEnvironmentProtectionDictionariesMapper.selectPage(page,entityWrapper);
    }


    @Override
    public List<HktsEnvironmentProtectionDictionaries> selectList(HktsEnvironmentProtectionDictionaries hktsEnvironmentProtectionDictionaries){
            QueryWrapper<HktsEnvironmentProtectionDictionaries> query=Wrappers.query();
            QueryWrapper<HktsEnvironmentProtectionDictionaries> entityWrapper=getEntityWrapper(query, hktsEnvironmentProtectionDictionaries);
            return hktsEnvironmentProtectionDictionariesMapper.selectList(entityWrapper);
    }

    /**
     *  公共查询条件
     * @param entityWrapper
     * @return
     */
    public QueryWrapper<HktsEnvironmentProtectionDictionaries> getEntityWrapper(QueryWrapper<HktsEnvironmentProtectionDictionaries> entityWrapper,HktsEnvironmentProtectionDictionaries hktsEnvironmentProtectionDictionaries){
            //条件拼接
                    if(StringUtils.isNotBlank(hktsEnvironmentProtectionDictionaries.getTableDescribe())){
                    entityWrapper.like(HktsEnvironmentProtectionDictionaries.TABLE_DESCRIBE,hktsEnvironmentProtectionDictionaries.getTableDescribe());
                    }
                    if(StringUtils.isNotBlank(hktsEnvironmentProtectionDictionaries.getTableName())){
                    entityWrapper.like(HktsEnvironmentProtectionDictionaries.TABLE_NAME,hktsEnvironmentProtectionDictionaries.getTableName());
                    }
                    if(StringUtils.isNotBlank(hktsEnvironmentProtectionDictionaries.getWorkShop())){
                    entityWrapper.like(HktsEnvironmentProtectionDictionaries.WORK_SHOP,hktsEnvironmentProtectionDictionaries.getWorkShop());
                    }

                    if(StringUtils.isNotBlank(hktsEnvironmentProtectionDictionaries.getIsExport())){
                    entityWrapper.eq(HktsEnvironmentProtectionDictionaries.IS_EXPORT,hktsEnvironmentProtectionDictionaries.getIsExport());
                    }

                    if(StringUtils.isNotBlank(hktsEnvironmentProtectionDictionaries.getIsEnable())){
                    entityWrapper.eq(HktsEnvironmentProtectionDictionaries.IS_ENABLE,hktsEnvironmentProtectionDictionaries.getIsEnable());
                    }
            return entityWrapper;
    }

    @Override
    public HktsEnvironmentProtectionDictionaries getDbTable() {
        QueryWrapper<HktsEnvironmentProtectionDictionaries> query = Wrappers.query();
        query.lambda().eq(HktsEnvironmentProtectionDictionaries::getWorkShop, "3")
        .eq(HktsEnvironmentProtectionDictionaries::getIsEnable,"1");
        HktsEnvironmentProtectionDictionaries hktsEnvironmentProtectionDictionaries = hktsEnvironmentProtectionDictionariesMapper.selectOne(query);
        return hktsEnvironmentProtectionDictionaries;
    }
}
